 
import { PositionHelper } from "utils/position/PositionHelper";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";
import { EActionCode } from "framework/FSM/Action/ActionCode";

/**
 * 移动到中央房 星门
 */
export class ActionMoveToCenterPortal  extends ActionBaseOfCreep<IActionCMD<"movetoPortal">>
{
    protected _execute(action: IActionCMD<"movetoPortal">): ActionCode 
    {
        const centerroom = action.arg.room; // 中央房名
        const room = Game.rooms[centerroom];
        const centerP = PositionHelper.Create({x:25,y:25,roomName:centerroom});
        if(room )
        {
            // 有视野
            const portal = room.getStructures(STRUCTURE_PORTAL)[0];
            action.arg.entity.mymoveTo({pos:portal.pos,range:0},{IsRealtime:true,IsPassPortal:true});
            if(action.arg.entity.pos.distance(portal.pos )==0)
            {
                return EActionCode.OK;
            }
            else 
            {

            }
        }
        else 
        {
            // 无视野
           
            if(action.arg.entity.pos.distance(centerP)>22)
            {
                action.arg.entity.mymoveTo({pos:centerP,range:10},{IsRealtime:true,IsPassPortal:true});
            }
            else 
            {
                 
            }
        }
        return  EActionCode.RUNNING;
    }
}